<template>
  <div>
    <div class="result-box" v-if="!search.isNull">
      <ul class="result">
        <li v-for="(item, index) in search.searchRes" :key="index">
          <router-link :to="{ path: '/detail/songs', query: { id: item.id } }">
            <div class="songs">
              <span>{{ item.name }}</span
              >-<span>{{ item.artists }}</span>
            </div>
          </router-link>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "appSearch",
  computed: {
    ...mapState(["search"]),
  },
};
</script>

<style lang="scss" scoped>
// 搜索结果
.result-box {
  width: 100%;
  margin-bottom: 150px;
  padding-top: 5px;
  box-sizing: border-box;
  overflow: hidden;
  .result {
    width: 100%;
    overflow: hidden;
    li {
      margin: 0 15px;
      border-radius: 5px;
      margin-bottom: 8px;
      background-color: #414141;
      a {
        color: white;
        .songs {
          height: 38px;
          line-height: 38px;
          font-size: 16px;
          padding: 0 15px;
          box-sizing: border-box;
          display: flex;
          align-items: center;
          overflow: hidden;
          span:nth-child(1) {
            flex-shrink: 0;
            margin-right: 15px;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          span:nth-child(2) {
            margin-left: 15px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }
      }
    }
  }
}
</style>